<!--用户管理-->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="superTablePage">
    </ex_super_table_page>

    <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" width="540px" :close-on-click-modal="false">
      <el-form ref="formEl" :model="formValue" :rules="rules" label-width="120px" class="common-form-panel-div"
               style="padding: 0px 10px; margin-top: 10px; ">

        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_subject_item_code')">
              <el-input v-model="formValue.subjectCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_subject_item_name')">
              <el-input v-model="formValue.subjectName"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_subject_item_remark')">
              <el-select v-model="formValue.subjectType" :placeholder="$tt('tip_please_select')" style="width: 100%;">
                <el-option
                  v-for="item in [{label: '收入', value: 'INCOME'},{label: '支出', value: 'OUTLAY'},{label: '资产', value: 'ASSET'}]"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>

            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_subject_item_remark')">
              <el-input v-model="formValue.remark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">{{ $tt('label_fms_account_config_cancel') }}</el-button>
        <el-button type="primary" @click="submitForm">{{ $tt('label_fms_account_config_cancel') }}</el-button>
      </div>
    </el-dialog>


  </div>
</template>
<script>

  let moduleName = "label_fms_income_compare_bill_manager"
  import superTablePageFunction from '@/mixin/super-table-page-function';
  export default {

    title: moduleName,
    components: {},

    mixins:[superTablePageFunction],
    data() {

      let _this = this

      return {

        formModel: 'insert/update',

        userTypeArr: [{id: 'ADMIN', name: '管理员'}, {id: 'OPERATOR', name: '操作员'}],
        roleSystemArr: [{id: 'WMS', name: 'WMS'}, {id: 'TMS', name: 'TMS 运输系统'}, {id: 'OMS', name: '业务后台系统'}],
        roleSystemMap: {},

        dialogFormVisible: false,
        dialogTitle: '',
        formValue: {},
        rules: {
          companyName: [
            {required: true, message: '请输入企业名称', trigger: 'blur'},
            {min: 3, max: 32, message: '长度在 3 到 32 个字符', trigger: 'blur'}
          ],
          companyShortCode: [
            {required: true, message: '请输入企业编码', trigger: 'blur'},
            {min: 3, max: 16, message: '长度在 3 到 16 个字符', trigger: 'blur'}
          ]
        }


      };
    },


    watch: {
      'formValue.companyId'(val, old) {

      }
    },

    created() {

      let _this = this

      _this.roleSystemMap = {}
      _this.roleSystemArr.forEach(e => {
        _this.roleSystemMap[e.id] = e.name
      })

      _this.option = {
        search: {
          model: [
            {label: "label_fms_bank_card_keyword", key: "keyword",},
            {
              label: "label_status", key: "status", type: 'select', enum: 'IsAvailableStatusEnum', attrs: { clearable: true }
            }
          ],
        },
        action: [
          {
            label: 'label_fms_subject_add_item', auth:'fms_income_income_compare_edit',attrs: {icon: "el-icon-plus"}, click: () => {
              this.dialogTitle = this.$tt('label_fms_subject_add_item')
              this.dialogFormVisible = true
              this.formValue = {}
            }
          },
        ],

        table: {
          url: "/fms-api/agent/AgentSubjectRpc/select.json",
          attrs: {
            'cell-style': ({row, column, rowIndex, columnIndex}) => {
              if (column.property == 'status') {
                return {color: row.status == 'NORMAL' ? this.$globalCss.successColor : this.$globalCss.infoColor}
              }
            }
          },
          model: [
            {key: 'subjectCode', label: 'label_fms_subject_item_code', align: 'left'},
            {key: 'subjectName', label: 'label_fms_subject_item_name', align: 'left'},
            {
              key: 'subjectType', label: 'label_fms_service_code_type', align: 'left',
              attrs: {
                formatter: (r, c, v, i) => {
                  return this.$enumShow(v, 'FmsSubjectTypeEnum')
                }
              }
            },
            {
              key: 'status', label: 'label_status',
              width: 120,
              attrs: {
                formatter: (r, c, v, i) => {
                  return this.$enumShow(v, 'IsAvailableStatusEnum')
                }
              }
            },
            {
              type: 'operate', width: 220,
              operate: [

                {
                  label: 'IsAvailableStatusEnum__DISABLED',auth:'fms_income_income_compare_disable',
                  type: "confirm-button",
                  message: 'label_fms_bank_card_confirm_forbidden',
                  url: '/fms-api/agent/AgentSubjectRpc/disable.json',
                  if: (row) => {
                    return row.status == 'ENABLE'
                  },
                  params: (v) => {
                    return {id: v.id}
                  },
                  done: ['reload', 'tip'],
                },
                {
                  label: 'IsAvailableStatusEnum__ENABLE',auth:'fms_income_income_compare_disable',
                  type: "confirm-button",
                  message: 'label_fms_bank_card_confirm_enable',
                  url: '/fms-api/agent/AgentSubjectRpc/enable.json',
                  if: (row) => {
                    return row.status != 'ENABLE'
                  },
                  params: (v) => {
                    return {id: v.id}
                  },
                  done: ['reload', 'tip']
                },
                {
                  label: 'label_edit',auth:'fms_income_income_compare_edit', click: (row) => {
                    this.dialogTitle = this.$tt('label_edit')
                    this.formValue = JSON.parse(JSON.stringify(row))
                    this.dialogFormVisible = true
                  }
                },
                {
                  label: 'label_delete',auth:'fms_income_income_compare_delete',
                  type: "confirm-button",
                  url: '/fms-api/agent/AgentSubjectRpc/remove.json',
                  message: 'label_fms_bank_card_confirm_delete',
                  params: (v) => {
                    return {id: v.id}
                  },
                  done: ['reload', 'tip']
                }
              ],
            }
          ]
        }
      }


    },

    props: {},

    destroyed() {

    },

    methods: {

      submitForm() {

        let _this = this

        _this.$refs['formEl'].validate((valid) => {
          if (valid) {

            _this.$ajax({
              url: '/fms-api/agent/AgentSubjectRpc/saveUpdate.json',
              type: 'json',
              data: _this.formValue,
              success: (responseData) => {
                this.$message({
                  showClose: true,
                  message: '提交成功',
                  type: 'success'
                })
                _this.$refs['superTablePage'].reload()
                _this.dialogFormVisible = false
              }
            });

          } else {
            return false;
          }

        });

      }


    }
  };

</script>
<style>
  .small-btn span {
    font-size: 14px;
  }

  .small-btn .el-button--small span {
    font-size: 14px;
  }
</style>
